// pages/detail1/detail1.js

const app = getApp()
var landui = require("../../utils/util.js");
const innerAudioContext = wx.createInnerAudioContext();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    domain: app.globalData.domain,
    trueDomain: app.globalData.trueDomain,
    keshi:'科室',
    info:[],
    list_same: [],
    length:0,
    hospital_info:[],
    current_nav: 'interview',
    option: 'pause',
    status: 'play'
  },


  // 播放音频
  playInnerAudio: function (e) {

    let that = this;
    let src = e.currentTarget.dataset.src;
    let idName = e.currentTarget.dataset.id_name;
    //console.log(src);
    //console.log(idName);

    innerAudioContext.autoplay = true
    innerAudioContext.src = src
    innerAudioContext.obeyMuteSwitch = false
    wx.createInnerAudioContext().title = 123
    if (that.data.option == 'pause') {
      innerAudioContext.play();
      //console.log('播放');
      that.setData({
        option: 'play'
      })
    } else {
      innerAudioContext.pause();
      //console.log('暂停');
      that.setData({
        option: 'pause'
      })
    }

    innerAudioContext.onError((res) => {
      //console.log(res.errMsg)
      //console.log(res.errCode)
    })
  },

  /**
   * ♢
   * http://jk.hnla.cn/api/getAudios  相关音频
   * 音频详情 http://jk.hnla.cn/api/audios/{id}?include=expert,expert.title,expert.department
   * include: 'expert,expert.title,expert.department'
   */
  onLoad: function (options) {
    var that = this;
    //文章详情
    landui.common.post({
      module: 'audios/' + options.id,
      param: { include: 'expert,expert.title,expert.department' },
      success: function (res) {
        res.data.add_time = res.data.add_time.substring(0,10);
        console.log(res.data);
        that.setData({
          info: res.data
        })
      },
      fail: function () {
      }
    });
    landui.common.post({
      module: 'queryExpert/',
      param: { include: 'title,department', id: options.id},
      success: function (res) {
       
        that.setData({
          hospital: res.data[0]
        })
      },
      fail: function () {
      }
    });
    // 相关专访  http://jk.hnla.cn/api/getAudios?number=3&classify=1
    landui.common.post({
      module: 'getAudios',
      param: { include: 'expert,expert.title,expert.department', number:3},
      success: function (res) {
        console.log(res.data);
        that.setData({
          list_same: res.data,
          length:res.data.length
        })
      },
      fail: function () {
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },


  onUnload:function() {
    innerAudioContext.pause();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },



  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})